package com.example.ccj.b.c.custom.tree.tree2;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.example.ccj.R;
import com.example.ccj.b.c.custom.tree.TreeMode;
import com.example.ccj.b.c.dialog.DialogBase;
import com.example.ccj.b.c.recycler.BaseRecycler;

import java.util.List;


/**
 * 显示选项可关联以及已关联的字段dialog
 * 点击后返回
 */
public class ShowSelectedTreeDialog extends DialogBase {

    List<TreeMode> treeModes;
    boolean isCanSelectRenYun;

    ISelectedTreeDataResult iSelectedTreeDataResult;
    /**
     *
     * @param context 上下文
     */
    public ShowSelectedTreeDialog(@NonNull Context context, List<TreeMode> treeModes,boolean isCanSelectRenYun,ISelectedTreeDataResult iSelectedTreeDataResult) {
        super(context);
        this.treeModes = treeModes;
        this.isCanSelectRenYun = isCanSelectRenYun;
        this.iSelectedTreeDataResult = iSelectedTreeDataResult;
    }

    boolean isModify = false;

    @Override
    public void onInit() {
        isCanClose(true);
        setLayout(R.layout.dialog_selected_tree);
        setAlpha(1f);//透明度
        isCanClose(true);//点击允许关闭
        isShowBackground(false);//不显示背景
        setShowHeightRatio(true);//按比例显示
        setHeightRatio(0.5);//高度显示比例
        showInBottom();//底部弹出
        setFull(true);//是否铺满
        goneTitleLeftImage();

        setTitleCenterText("已选择的");
        setTitleRightText("OK").setOnClickListener(V-> {
            if (isModify && iSelectedTreeDataResult != null) iSelectedTreeDataResult.onResult();
            dismiss();
        });

        BaseRecycler<TreeMode> fieldBaseRecycler = findViewById(R.id.dialog_selected_tree_rec);
        fieldBaseRecycler.setLayoutManager(new LinearLayoutManager(getContext()));
        fieldBaseRecycler.setAdapter(treeModes,new TreeStructureSelectTreeAdapter(treeModes, new ITreeResultListener() {
            @Override
            public void onNext(TreeMode treeMode) {

            }

            @Override
            public void onSelectChange(TreeMode treeMode, boolean isSelect) {
                isModify = true;
            }
        }, isCanSelectRenYun,true, true));
    }

}
